﻿Public Class frmDepositoListado

    Private Sub frmClientesListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgVendedor.AutoGenerateColumns = False
        CargarDepositos()
    End Sub

    Dim controller As New ControllerSigeco.controller_stock()

    Private m_frmDeposito As frmDeposito
    Public Property frmDepositosForm() As frmDeposito
        Get
            Return m_frmDeposito
        End Get
        Set(ByVal value As frmDeposito)
            m_frmDeposito = value
        End Set
    End Property

    Private Sub CargarDepositos()

        Dim dt As New DataTable
        dt = controller.get_depositos(oiml.dbConn, 0, txtDeposito.Text, txtUbicacion.Text, Not cbxHabilitado.Checked)
        dgVendedor.DataSource = dt

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgVendedor.SelectedRows.Count > 0 Then
                Dim cod As New Integer
                cod = dgVendedor.SelectedRows(0).Cells(0).Value

                If frmDepositosForm Is Nothing Then

                    frmDepositosForm = New frmDeposito
                    frmDepositosForm.idDeposito = cod

                    'If frmClientes.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmDepositosForm.ShowDialog()
                    CargarDepositos()
                    frmDepositosForm.Dispose()
                    frmDepositosForm = Nothing
                    'End If
                Else
                    frmDepositosForm.idDeposito = cod
                    frmDepositosForm.ShowDialog()
                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarDepositos()
    End Sub

    Private Sub txtProveedor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDeposito.KeyDown, txtUbicacion.KeyDown, cbxHabilitado.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarDepositos()

        End If
    End Sub

    Private Sub dgCliente_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgVendedor.DoubleClick
        btnEditar_Click(sender, e)
    End Sub

    Private Sub dgCliente_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgVendedor.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If

    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        frmDepositosForm = New frmDeposito()
        frmDepositosForm.idDeposito = 0
        frmDepositosForm.ShowDialog()
        CargarDepositos()
    End Sub

End Class